from collections import defaultdict

class Solution(object):
    def firstUniqChar(self, s):
        """
        :type s: str
        :rtype: int
        """
        lookup = defaultdict(int)
        candidtates = set()

        for i, c in enumerate(s):
            if lookup[c]:
                candidtates.discard(lookup[c])
            else:
                lookup[c] = i+1
                candidtates.add(i+1)

        return min(candidtates)-1 if candidtates else -1






    """
        Time Complexity = O(n)
        Space Complexity = O(n)

        Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.

        Example:
        s = "leetcode"
        return 0.

        s = "loveleetcode",
        return 2.
    """
